package com.shujia.kafka

import org.apache.kafka.clients.producer.{KafkaProducer, ProducerRecord}

import java.util.Properties

object Demo1Producer {
  def main(args: Array[String]): Unit = {

    /**
     * 1、建立链接
     */

    val properties = new Properties()
    //指定kafka集群列表
    properties.setProperty("bootstrap.servers", "master:9092,node1:9092,node2:9092")

    //设置key 和value的序列化类
    properties.setProperty("key.serializer", "org.apache.kafka.common.serialization.StringSerializer")
    properties.setProperty("value.serializer", "org.apache.kafka.common.serialization.StringSerializer")


    //创建生产者
    val producer = new KafkaProducer[String, String](properties)

    //狗酱一行数据
    val record = new ProducerRecord[String, String]("test_topic", "java")

    //将数据发送到kafka中
    producer.send(record)

    //关闭链接
    producer.close()

  }

}
